package com.ibiaoke.marketing.service;

import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.marketing.dao.ShareCouponRelDao;
import com.ibiaoke.marketing.entity.ShareCouponRel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 分享优惠券关联service
 */
@Service
public class ShareCouponRelServiceImpl implements ShareCouponRelService {

    @Autowired
    private ShareCouponRelDao shareCouponRelDao;

    /**
     * 保存分享优惠券关联方法
     * @param shareCouponRel
     * @return
     */
    @Override
    public int saveShareCouponRel(ShareCouponRel shareCouponRel) {
        shareCouponRel.setCreateTime(new Date());
        shareCouponRel.setUpdateTime(new Date());
        AssertUtils.notNull(shareCouponRel.getCouponId(), "关联优惠券Id不能为空");
        AssertUtils.notNull(shareCouponRel.getMarketingId(), "关联营销id不能为空");
        AssertUtils.notNull(shareCouponRel.getNum(), "满赠数量不能为空");
        return shareCouponRelDao.insert(shareCouponRel);
    }

    /**
     * 更新分享优惠券关联
     * @param shareCouponRel
     * @return
     */
    @Override
    public int updateShareCouponRel(ShareCouponRel shareCouponRel) {
        AssertUtils.notNull(shareCouponRel.getId(), "id不能为空");
        shareCouponRel.setUpdateTime(new Date());
        return shareCouponRelDao.updateByPrimaryKeySelective(shareCouponRel);
    }

    /**
     * 查询列表
     * @param marketingId
     * @param couponId
     * @return
     */
    @Override
    public List<ShareCouponRel> listShareCouponRel(Integer marketingId, Integer couponId) {
        return shareCouponRelDao.listShareCouponRel(marketingId, couponId);
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @Override
    public ShareCouponRel getShareCouponRel(Integer id) {
        AssertUtils.notNull(id, "id不能为空");
        return shareCouponRelDao.selectByPrimaryKey(id);
    }


}
